Skip to content

[flang][runtime] Use fallback bessel functions when not available in libm #101437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Calandracas606
Copy link
Contributor

Fixes compilation on linux when using musl as the libc.

musl does not provide long double variants of the bessel functions.

Fixes compilation on linux when using musl as the libc.

musl does not provide long double variants of the bessel functions.
@llvmbot llvmbot added flang:runtime flang Flang issues not falling into any other category labels Aug 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2024

@llvm/pr-subscribers-flang-runtime

Author: Daniel Martinez (Calandracas606)

Changes

Fixes compilation on linux when using musl as the libc.

musl does not provide long double variants of the bessel functions.


Full diff: https://github.com/llvm/llvm-project/pull/101437.diff

2 Files Affected:

  • (modified) flang/runtime/Float128Math/CMakeLists.txt (+20)
  • (modified) flang/runtime/Float128Math/math-entries.h (+4)
diff --git a/flang/runtime/Float128Math/CMakeLists.txt b/flang/runtime/Float128Math/CMakeLists.txt
index a5f5bec1e7e4b..b7d890df1f4aa 100644
--- a/flang/runtime/Float128Math/CMakeLists.txt
+++ b/flang/runtime/Float128Math/CMakeLists.txt
@@ -108,6 +108,26 @@ elseif (HAVE_LDBL_MANT_DIG_113)
   # We can use 'long double' versions from libc.
   check_library_exists(m sinl "" FOUND_LIBM)
   if (FOUND_LIBM)
+    check_cxx_source_compiles(
+      "#include <cmath>
+       int main() {
+         int n = 0;
+         long double x = 1;
+         long double Y0 = y0l(x);
+         long double Y1 = y1l(x);
+         long double Yn = ynl(n,x);
+         long double J0 = j0l(x);
+         long double J1 = j1l(x);
+         long double Jn = jnl(n,x);
+         return 0;
+       }
+      "
+    FOUND_LIBM_BESSEL)
+    if (FOUND_LIBM_BESSEL)
+     target_compile_definitions(FortranFloat128MathILib INTERFACE
+       HAS_LIBM_BESSEL
+       )
+    endif()
     target_compile_definitions(FortranFloat128MathILib INTERFACE
       HAS_LIBM
       )
diff --git a/flang/runtime/Float128Math/math-entries.h b/flang/runtime/Float128Math/math-entries.h
index 13fdab2647003..45ae40fdafa0e 100644
--- a/flang/runtime/Float128Math/math-entries.h
+++ b/flang/runtime/Float128Math/math-entries.h
@@ -185,9 +185,11 @@ DEFINE_SIMPLE_ALIAS(Hypot, std::hypot)
 DEFINE_SIMPLE_ALIAS(Ilogb, std::ilogb)
 DEFINE_SIMPLE_ALIAS(Isinf, std::isinf)
 DEFINE_SIMPLE_ALIAS(Isnan, std::isnan)
+#ifdef HAS_LIBM_BESSEL
 DEFINE_SIMPLE_ALIAS(J0, j0l)
 DEFINE_SIMPLE_ALIAS(J1, j1l)
 DEFINE_SIMPLE_ALIAS(Jn, jnl)
+#endif
 DEFINE_SIMPLE_ALIAS(Ldexp, std::ldexp)
 DEFINE_SIMPLE_ALIAS(Lgamma, std::lgamma)
 DEFINE_SIMPLE_ALIAS(Llround, std::llround)
@@ -204,9 +206,11 @@ DEFINE_SIMPLE_ALIAS(Tan, std::tan)
 DEFINE_SIMPLE_ALIAS(Tanh, std::tanh)
 DEFINE_SIMPLE_ALIAS(Tgamma, std::tgamma)
 DEFINE_SIMPLE_ALIAS(Trunc, std::trunc)
+#ifdef HAS_LIBM_BESSEL
 DEFINE_SIMPLE_ALIAS(Y0, y0l)
 DEFINE_SIMPLE_ALIAS(Y1, y1l)
 DEFINE_SIMPLE_ALIAS(Yn, ynl)
+#endif
 
 // Use numeric_limits to produce infinity of the right type.
 #define F128_RT_INFINITY \

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:runtime flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants